<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/17/017
 * Time: 16:31
 */

namespace app\portal\model;



use think\Model;

class VideoPostModel extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;
    /**
     * 后台管理添加视频
     * @param array $data 视频数据
     * @return $this
     */
    public function addVideo( $data )
    {
        if (!empty($data['thumbnail'])) {
            $data['thumbnail'] = cmf_asset_relative_url($data['thumbnail']);
        }
        if (!empty($data['post_video'])) {
            $data['post_video'] = cmf_asset_relative_url($data['post_video']);
        }
        $this->allowField(true)->data($data,true)->isUpdate(false)->save();
        return $this;
    }

    /**
     * 后台管理修改视频
     * @param array $data 视频数据
     * @return $this
     */
    public function editVideo( $data )
    {
        if (!empty($data['thumbnail'])) {
            $data['thumbnail'] = cmf_asset_relative_url($data['thumbnail']);
        }
        if (!empty($data['post_video'])) {
            $data['post_video'] = cmf_asset_relative_url($data['post_video']);
        }
        $this->allowField(true)->isUpdate(false)->save($data, ['id' => $data['id']]);;
        return $this;
    }
}